package com.mmlc.utils;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;

import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.meimei.lichengkongjian.R;

/**
 * Created by Administrator on 2016/7/27.
 */
public class SelectorUtils {
    public static Context context = App.context;

    public static final int Color_Red_Gray = 1;
    public static final int Color_White_Gray = 2;
    public static final int shape_GrayStroke_Gray = 3;

    public static StateListDrawable getSelector(int type){

        StateListDrawable drawable = new StateListDrawable();
        Drawable[] drawables = null;
        switch (type){
            case Color_Red_Gray:
                drawables = getColorDrawable(R.color.color_red_F6060C,R.color.color_gray_B7B7B7);
                break;
            case Color_White_Gray:
                drawables = getColorDrawable(R.color.color_white_FFFFFF,R.color.color_gray_B7B7B7);
                break;
            case shape_GrayStroke_Gray:
                drawables = getShapeDrawable(R.drawable.shape_stroke_gray,R.drawable.shape_no_stroke_gray);
                break;
        }


        if(drawables != null){
            //defalut
            drawable.addState(new int[]{-android.R.attr.state_pressed},
                    drawables[0]);

            //Pressed
            drawable.addState(new int[]{android.R.attr.state_pressed},
                    drawables[1] );
        }


        return drawable;
    }

    public static ColorDrawable[] getColorDrawable(int defaultColor,int preColor){
        ColorDrawable[] colorDrawables = new ColorDrawable[2];

        ColorDrawable value0 = new ColorDrawable(context.getResources().getColor(defaultColor));
        ColorDrawable value1 = new ColorDrawable(context.getResources().getColor(preColor));

        colorDrawables[0] = value0;
        colorDrawables[1] = value1;
        return colorDrawables;
    }
    public static Drawable[] getShapeDrawable(int defaultDrawable, int preColor){
        Drawable[] shapeDrawables = new Drawable[2];
        Drawable value0 = context.getResources().getDrawable(defaultDrawable);
        Drawable value1 = context.getResources().getDrawable(preColor);

        shapeDrawables[0] = value0;
        shapeDrawables[1] = value1;
        return shapeDrawables;
    }
}
